﻿//功能描述：项目前期信息数据访问层
using Hong.IRepository.IRepository_CustomerManagement;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dapper;
using System.Data;
using System.Data.SqlClient;
using Hong.Model.SysDomain.Model_CustomerManagement;
using Microsoft.Extensions.Configuration;
using Hong.Common.Encryption;

namespace Hong.Repository.Repository.Repository_CustomerManagement
{
    public class CustinformationRepository : ICustinformationRepository
    {
        #region 构造器注入
        //注入解密SQL连接字符串
        private readonly SecurityStatic _securityStatic;
        public CustinformationRepository(SecurityStatic securityStatic)
        {
            _securityStatic = securityStatic;
        }
        #endregion
        #region 项目前期信息
        #region 项目前期信息的显示查询
        /// <summary>
        /// 文档信息显示查询
        /// </summary>
        /// <returns></returns>
        public List<Accessory> GetAccessory(string acsoryIdNmae, DateTime? acsoryIdTime, int pageIndex, int pageSize, out int totalCount)
        {
            using (IDbConnection conn = new SqlConnection(_securityStatic.Securityinfo()))
            {
                var sql = "select * from Accessory where 1=1 ";
                if (!string.IsNullOrEmpty(acsoryIdNmae))
                {
                    sql += $" and acsoryIdNmae='{acsoryIdNmae}'";
                }
                if (acsoryIdTime != null)
                {
                    sql += $" and acsoryIdTime='{acsoryIdTime}'";
                }
                totalCount = conn.Query<Accessory>(sql).Count();
                sql += $" order by acsoryId offset {pageIndex - 1}*{pageSize} rows fetch next {pageSize} row only";
                var query = conn.Query<Accessory>(sql).ToList();
                return query;
            }
        }
        #endregion

        #region 项目前期信息的批量操作
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public int DeleteAccessory(string ids)
        {
            using (IDbConnection conn = new SqlConnection(_securityStatic.Securityinfo()))
            {
                string[] str = ids.Split(',');
                foreach (var item in str)
                {
                    var sql = $"delete from Accessory where acsoryId='{item}'";
                    conn.Execute(sql);
                }
                return 1;
            }
        }
        #endregion
        #endregion


    }
}
